// 故障快照中,点击问题详情页面
<template>
  <div class="box">
    <el-dialog title="问题列表详情" :visible.sync="problemCountData.contractDialogVisible" width="1100px" @close="dialogClose">
      <div class="dialogText">
        <el-row class="detailsRow rowRelative">
          <el-col :span="12">
            <div class="details-row vrowRelative">
              <span>设备名称：</span>
              <span>{{ problemCountData.contractDetailList.zcmc }}</span>
            </div>
            <div class="details-row rowRelative">
              <span>设备IP：</span>
              <span> {{ problemCountData.contractDetailList.ip }}</span>
            </div>
            <div class="details-row rowRelative">
              <span>辖区：</span>
              <span
                >{{ problemCountData.contractDetailList.sfmc }}{{ problemCountData.contractDetailList.csmc }}{{ problemCountData.contractDetailList.qxmc }}{{ problemCountData.contractDetailList.xzjd
                }}{{ problemCountData.contractDetailList.xxdz }}
              </span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="details-row rowRelative">
              <span>设备类型：</span>
              <span
                >{{ problemCountData.contractDetailList.zclxmc1 ? problemCountData.contractDetailList.zclxmc1 + ' / ' : ''
                }}{{ problemCountData.contractDetailList.zclxmc2 ? problemCountData.contractDetailList.zclxmc2 + ' / ' : '' }}{{ problemCountData.contractDetailList.zclxmc }}</span
              >
            </div>
            <div class="details-row rowRelative">
              <span>品牌：</span>
              <span>{{ problemCountData.contractDetailList.ppmc }}</span>
            </div>
            <div class="details-row rowRelative">
              <span>型号：</span>
              <span>{{ problemCountData.contractDetailList.xh }}</span>
            </div>
          </el-col>
        </el-row>
        <!-- 搜索条件 -->
        <el-form :inline="true" :model="searchCriteria" class="demo-form-inline">
          <el-form-item label="问题类型:">
            <el-select v-model="searchCriteria.region" :no-data-text="tiText1" class="inputWidth" filterable clearable placeholder="请选择">
              <el-option v-for="item in lbmcOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="生成故障:">
            <el-select v-model="searchCriteria.isGZ" class="inputWidth" clearable placeholder="请选择/搜索">
              <el-option label="未生成" value="0"></el-option>
              <el-option label="已生成" value="1"></el-option>
              <el-option label="已解决" value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="问题时间:">
            <el-date-picker
              v-model="searchCriteria.dataTime"
              :picker-options="pickerBeginDateBefore"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" class="btnSizeStyle" @click="onSubmit()">查询</el-button>
          </el-form-item>
        </el-form>
        <!-- @row-dblclick="rowClick_details" -->
        <el-table ref="pilian" :data="gridDataTable" @select="isCheck" @select-all="isCheckAll" v-loading="tableLoad" border :header-cell-style="{ backgroundColor: '#ECF3FC' }" minHeight="250">
          <el-table-column type="selection" width="45" :selectable="checkboxT_details"></el-table-column>
          <el-table-column type="index" label="序号" min-width="50" align="center" />
          <!-- <el-table-column property="zsxm" :label="problemCountData.type === '设备' ? '故障类型' : '问题类型'" min-width="250">
            <template slot-scope="scope">{{ scope.row.lbmcs + ' / ' + scope.row.lbmc }}</template>
          </el-table-column> -->
          <!-- <el-table-column :label="problemCountData.type === '设备' ? '故障描述' : '问题描述'" min-width="250">
            <template slot-scope="scope">
              <span>{{ problemCountData.type === '设备' ? scope.row.gzms : scope.row.wtz }}</span>
            </template>
          </el-table-column> -->
          <el-table-column label="问题类型" min-width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.lxmcs }}/{{ scope.row.wtlxmc }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="问题次数" min-width="100">
            <template slot-scope="scope">
              <span class="haveLinks">{{ scope.row.wtjs }}</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="问题次数" min-width="88"> -->
          <!-- 更新于2021/04/23 -->
          <el-table-column label="问题发生次数" min-width="88">
            <template slot-scope="scope">
              <span :class="[scope.row.lxid === 1 || scope.row.wtlx_BM === 37 ? '' : 'haveLinks']" @click="countBtn(scope.row)">{{ scope.row.wtjs }}</span>
              <el-tooltip class="item" effect="dark" content="近30分钟内没有记录" placement="top-start" v-if="scope.row.lxid === 1 || scope.row.wtlx_BM === 37">
                <i class="el-icon-warning-outline" style="font-size: 15px; color: #7f7f7f; padding-left: 5px"></i>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="问题描述" min-width="200">
            <template slot-scope="scope">
              <span>{{ scope.row.wtz }}</span>
            </template>
          </el-table-column>
          <el-table-column label="问题来源" min-width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.wtly }}</span>
            </template>
          </el-table-column>
          <el-table-column property="wtscsj" :show-overflow-tooltip="true" label="问题时间" min-width="150">
            <template slot-scope="scope">
              <span>{{ scope.row.wtscsj | dateFormat }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="sfyscgz" label="故障" min-width="80">
            <template slot-scope="scope">
              <el-tag :type="gzTag[scope.row.sfyscgz].type">{{ gzTag[scope.row.sfyscgz].title }}</el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <el-row class="page-row noBorder">
        <el-col :span="12">
          <el-button type="primary" @click="addWithList('加入白名单')" class="btnSizeStyle" :disabled="deleteAll_details.length > 0 ? false : true">加入白名单</el-button>
        </el-col>
        <el-col :span="12">
          <!-- <el-button @click="problemCountData.contractDialogVisible = false" class="btnSizeStyle">取 消</el-button> -->
          <!-- <el-button type="primary" @click="problemCountData.contractDialogVisible = false" class="btnSizeStyle">关 闭</el-button> -->
          <el-pagination
            background
            layout="prev, pager, next, total"
            @current-change="addHandleCurrentChange2"
            :current-page.sync="addCurrentPage2"
            :page-size="addPageSize2"
            :total="addTotal2"
            :hide-on-single-page="paginationValue2"
          ></el-pagination>
        </el-col>
      </el-row>
      <!-- <div slot="footer" class="footerPagination">
        <div></div>
      </div> -->
    </el-dialog>
    <!-- 计数提示窗 -->
    <el-dialog title="问题次数详情" :visible.sync="dialogVisible_count" width="900px">
      <el-row class="detailsRow">
        <el-col :span="12">
          <div class="details-row">
            <span>设备名称：</span>
            <span>{{ detailsDate.zcmc }}</span>
          </div>
          <div class="details-row">
            <span>设备类型：</span>
            <span>
              {{ detailsDate.zclxmc1 ? detailsDate.zclxmc1 + ' / ' : '' }}
              {{ detailsDate.zclxmc2 ? detailsDate.zclxmc2 + ' / ' : '' }}
              {{ detailsDate.zclxmc }}
            </span>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="details-row">
            <span>设备IP：</span>
            <span>{{ detailsDate.ip }}</span>
          </div>
          <div class="details-row">
            <span>设备问题：</span>
            <span>{{ detailsDate.lxmcs + ' / ' + detailsDate.wtlxmc }}</span>
          </div>
        </el-col>
      </el-row>
      <el-alert title="只显示最近30分钟的问题历史数据。" :closable="false" type="warning" show-icon></el-alert>
      <!-- 表格 -->
      <el-table
        :data="gridData"
        :header-cell-style="{ backgroundColor: '#ECF3FC', color: '#333', height: '48px', borderBottom: '1px solid #CEE1F7' }"
        border
        highlight-current-row
        stripe
        v-loading="gridLoad"
        max-height="320px"
      >
        <template slot="empty">{{ gridMessage }}</template>
        <el-table-column type="index" label="序号" min-width="50" align="center" />
        <el-table-column min-width="170" property="date" label="问题时间" sortable>
          <template slot-scope="scope">
            <svg class="iconfont" aria-hidden="true" style="width: 12px; height: 12px; padding-right: 5px">
              <use :xlink:href="`#el-icon-my${Number(scope.row.dqzt) === 1 ? 'not_generated' : 'generated'}`" />
            </svg>
            <span>{{ scope.row.wtscsj | dateFormat }}</span>
          </template>
        </el-table-column>
        <el-table-column min-width="150" property="name" label="问题描述">
          <template slot-scope="scope">
            <span>{{ scope.row.wtz }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-row class="page-row noBorder" style="padding-top: 10px">
        <el-col :span="12">
          <el-pagination background @current-change="handleCurrentChange_details" :current-page="currentPage_details" layout=" prev, pager, next,total" :total="total_details"></el-pagination>
        </el-col>
        <el-col :span="12" style="height: 47px; display: table">
          <el-button type="primary" size="small" @click="dialogVisible_count = false" class="btnSizeStyle">关 闭</el-button>
        </el-col>
      </el-row>
    </el-dialog>
    <!-- 提示窗 -->
    <el-dialog title="加入白名单" :visible.sync="dialogVisible" width="576px">
      <span style="color: #5a5e66" v-html="tips"></span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" class="btnSizeStyle">取 消</el-button>
        <el-button type="primary" :loading="addWhiteListLoad" @click="submitok('加入白名单')" class="btnSizeStyle" v-preventReClick>确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { yeWu } from '@/utils/allUrl.js'
import { getUrl } from '@/utils/getUrl.js'
import { timeLoad, tableMessageText } from '@/assets/js/setTime'
// import countListVue from '../../RunTesting/countList.vue'
export default {
  props: ['problemCountData'],
  data() {
    return {
      gzTag: [
        {
          title: '未生成',
          type: 'danger',
        },
        {
          title: '已生成',
          type: 'primary',
        },
        {
          title: '已解决',
          type: 'success',
        },
      ],
      addCurrentPage2: 1, // 详情翻页
      addPageSize2: 5,
      addTotal2: 0, // 详情翻页
      paginationValue2: false, // 详情翻页数据为一条时隐藏
      gridDataTable: [], // 详情数据源
      zicanOptions: [], // 资产类型
      lbmcOptions: [], // 问题类型
      searchCriteria: {
        region: '', // 问题类型
        isGZ: '', // 生成故障
        dataTime: '', // 问题时间
      },
      tiText1: '暂无数据', // 问题类型提示
      tableLoad: false,
      gridMessage: '',
      gridLoad: false,
      gridData: [],
      gridTimer: null, // 计数定时器
      dialogVisible_count: false,
      detailsDate: {},
      currentPage_details: 1,
      total_details: 0,
      pickerBeginDateBefore: {
        // 设置只能选择到今天及以前的日期
        disabledDate(time) {
          return time.getTime() >= Date.now()
        },
      },
      deleteAll_details: [],
      tips: '',
      dialogVisible: false,
      addWhiteListLoad: false, // 加入白名单
      addWhiteListTime: null,
    }
  },
  watch: {
    problemCountData: {
      // 正确给 cData 赋值的 方法
      deep: true,
      handler: function (newVal, oldVal) {
        if (newVal.contractDialogVisible) {
          this.getshuList()
        }
      },
    },
    addWhiteListLoad(newVal, oldVal) {
      this.addWhiteListTime = setTimeout(() => {
        if (this.addWhiteListLoad) {
          this.addWhiteListLoad = false
        }
      }, timeLoad)
    }, // 弹窗
  },
  created() {
    this.getwenti()
    if (this.problemCountData.contractDialogVisible) {
      this.getshuList()
    }
  },
  mounted() {},
  methods: {
    checkboxT_details(row, index) {
      return true
      // console.log(row)
      // 0 未生成 1已生成
      // if (row.tatal > 0) {
      // return true
      // } else {
      //   return false
      // }
    },
    // 勾选
    isCheck(selection, row) {
      this.deleteAll_details = selection
    },
    // 全选
    isCheckAll(selection, row) {
      this.deleteAll_details = selection
    },
    rowClick_details(row, column, event) {
      const a = this.deleteAll_details.findIndex((item) => item.id === row.id)
      if (a !== -1) {
        this.deleteAll_details.splice(a, 1)
        this.$refs.pilian.toggleRowSelection(row, false)
      } else if (this.checkboxT_details(row, null)) {
        this.deleteAll_details.push(row)
        const s1 = new Set(this.deleteAll_details)
        this.deleteAll_details = [...s1]
        this.$refs.pilian.toggleRowSelection(row, true)
      }
    },
    dialogClose() {
      this.searchCriteria = {
        region: '', // 问题类型
        isGZ: '', // 生成故障
        dataTime: '', // 问题时间
      }
    },
    // 获取数据列表
    getshuList() {
      clearTimeout(this.tableTimer)
      this.tableLoad = true
      const params = new URLSearchParams()
      params.append('SB_ID', this.problemCountData.contractDetailList.id)
      //   params.append('sort', 'DESC')
      //   params.append('order', 'WTSCSJ')
      params.append('SFYSCGZ', this.searchCriteria.isGZ) // 生成故障
      params.append('M_', this.addCurrentPage2) // 当前页
      params.append('N_', this.addPageSize2) // 每页显示行数
      this.setList(params)
    },
    // 列表查询
    async setList(params) {
      this.deleteAll_details = []
      //   this.loadTable()
      //   this.tableLoad = true
      const { data: res } = await this.$http.post(`${yeWu}wtjs/selectWenTiJianSuo`, params)
      this.tableLoad = false
      if (res.code === '0014') {
        return ''
      } else if (res.code === '0013') {
        this.gridDataTable = []
        this.addTotal2 = 0
        return
      } else if (res.code !== '0000') {
        return this.$message({
          type: 'error',
          message: res.message,
          center: true,
        })
      }
      this.gridDataTable = res.data.list
      this.addTotal2 = res.data.countList
    },
    // 查询
    onSubmit() {
      this.tableLoad = true
      const { region, isGZ, dataTime } = this.searchCriteria
      const params = new URLSearchParams()
      console.log(this.problemCountData.contractDetailList.id)
      params.append('SB_ID', this.problemCountData.contractDetailList.id)
      //   params.append('sort', 'DESC')
      //   params.append('order', 'WTSCSJ')
      // params.append('SFYSCGZ', this.searchCriteria.isGZ)
      params.append('WTLXBM', region) // 问题类型
      params.append('SFYSCGZ', isGZ) // 生成故障
      if (dataTime) {
        // 问题时间
        params.append('WTSCSJStart', dataTime[0])
        params.append('WTSCSJEnd', dataTime[1])
      }
      params.append('M_', 1) // 当前页
      params.append('N_', this.addPageSize2) // 每页显示行数
      this.setList(params)
    },
    // 问题类型
    async getwenti() {
      const params = new URLSearchParams()
      params.append('FLBISNULL', 0)
      const { data: res } = await this.$http.post(`${yeWu}wtgzzd/selectWenTiGuZhangZiDian`, params)
      if (res.code !== '0000') {
        this.lbmcOptions = []
        this.tiText1 = res.message
      } else {
        res.data.list.forEach((item) => {
          const k = {
            value: item.id,
            label: item.lbmc,
          }
          this.lbmcOptions.push(k)
        })
      }
    },
    addHandleCurrentChange2(val) {
      this.addCurrentPage2 = val
      this.getshuList()
    },
    // 加入白名单/删除/生成故障
    async submitok() {
      var arr = []
      this.deleteAll_details.forEach((item) => {
        arr.push(item.id)
      })
      var user = JSON.parse(getUrl('userconter'))
      this.addWithListFun(user, arr)
    },
    // 加入白名单
    async addWithListFun(user, arr) {
      clearTimeout(this.addWhiteListTime)
      this.addWhiteListLoad = true
      const params = new URLSearchParams()
      params.append('USERID', user.id)
      params.append('ids', arr)
      const { data: res } = await this.$http.post(`${yeWu}wtjs/insertWTBMD`, params)
      this.addWhiteListLoad = false
      if (res.code === '0014') {
        return
      } else if (res.code !== '0000') {
        return this.$message({
          type: 'error',
          message: res.message,
          center: true,
        })
      }
      this.$message.success(res.message)
      this.getshuList()
      this.dialogVisible = false
      this.deleteAll_details = []
      this.$refs.pilian.clearSelection()
    },
    // 加入白名单
    addWithList(val) {
      this.deleteAll_details.some((item) => {
        // const s = this.deleteAll_details.some((item) => {
        // console.log(item)
        // return item.wtbmdjs > 0
        if (item.wtbmdjs > 0) {
          return this.$message({
            type: 'error',
            message: '您的选项中已加入白名单，请检查您的选中项',
            center: true,
          })
        } else {
          this.tips = `<svg
          class="iconfont"
          aria-hidden="true"
          style="width: 20px;height: 20px;vertical-align: middle;padding-right: 5px;"
        >
          <use xlink:href="#el-icon-mywarning" style="font-size:50px" />
        </svg>加入白名单成功后，所选设备及对应的问题类型系统将不再提醒，是否加入？`
          this.title = val
          this.dialogVisible = true
        }
      })
      // if (s) {
      //   return this.$message({
      //     type: 'error',
      //     message: '您的选项中已加入白名单，请检查您的选中项',
      //     center: true,
      //   })
      // } else {
      //   this.tips = `<svg
      //     class="iconfont"
      //     aria-hidden="true"
      //     style="width: 20px;height: 20px;vertical-align: middle;padding-right: 5px;"
      //   >
      //     <use xlink:href="#el-icon-mywarning" style="font-size:50px" />
      //   </svg>加入白名单成功后，所选设备及对应的问题类型系统将不再提醒，是否加入？`
      //   this.title = val
      //   this.dialogVisible = true
      // }
    },
    // 计数按钮
    countBtn(row) {
      if (row.lxid === 1 || row.wtlx_BM === 37) {
        return
      }
      this.currentPage_details = 1
      this.popoverShow(row)
      this.detailsDate = row
      this.dialogVisible_count = true
    },
    async popoverShow(row, M_) {
      clearTimeout(this.gridTimer)
      this.gridLoad = true
      this.gridTimer = setTimeout(() => {
        if (this.gridLoad) {
          // console.log('newVal', this.gridLoad, '---', tableMessageText)
          this.gridLoad = false
          this.gridData = []
          this.gridMessage = tableMessageText
        }
      }, timeLoad)
      this.gridMessage = ''
      const params = new URLSearchParams()
      params.append('WTLX_BM', row.wtlx_BM)
      params.append('SB_ID', row.sb_ID)
      params.append('M_', this.currentPage_details)
      params.append('N_', 10)
      const { data: res } = await this.$http.post(`${yeWu}wtjs/selectHistroy`, params)
      this.gridLoad = false
      switch (res.code) {
        case '0000':
          this.gridData = res.data.list
          this.total_details = res.data.count
          break
        default:
          this.gridData = []
          this.total_details = 0
          this.gridMessage = res.message
          break
      }
    },
    handleCurrentChange_details(val) {
      this.currentPage_details = val
      this.popoverShow(this.detailsDate)
    },
  },
}
</script>
<style lang="scss" scoped>
@import '@/assets/scss/xjzxCommon.scss';
@import '@/assets/scss/detailsRow.scss';
.detailsRow.el-row {
  padding-top: 0;
}
.el-alert {
  margin-bottom: 15px;
  height: 40px;
  border: 1px solid #f5e3bf;
  &.el-alert--warning.is-light {
    background-color: #fffbe6;
    color: #e28b02;
  }
}
.box {
  // width: 100%;
  // height: 100%;
  .dialogText {
    font-size: 14px;
    color: #333;
    .star {
      color: #f56c6c;
    }
    .contentFont {
      display: inline-block;
      width: 120px;
      color: #7a7a7a;
      text-align: right;
    }
    .lineHight .el-row {
      line-height: 30px;
    }
  }
}
</style>
